
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class LinkGetter {
	private Pattern htmltag;
	private Pattern link;
	private final String root;

	public LinkGetter(String root) {
		this.root = root;
		htmltag = Pattern.compile("<a\\b[^>]*href=\"[^>]*>(.*?)</a>");
		link = Pattern.compile("href=\"[^>]*\">");
	}

	public List<String> getLinks(String str) {
		List<String> links = new ArrayList<String>();
		

			Matcher tagmatch = htmltag.matcher(str);
			while (tagmatch.find()) {
				Matcher matcher = link.matcher(tagmatch.group());
				matcher.find();
				String link = matcher.group().replaceFirst("href=\"", "")
						.replaceFirst("\">", "");
				if (valid(link)) {
					links.add(str);
				}
			}
		return links;
	}

	private boolean valid(String s) {
		if (s.matches("javascript:.*|mailto:.*")) {
			return false;
		}
		return true;
	}

	
	
	public static void main(String[] args) {
		System.out.println(new LinkGetter("sdf").getLinks("<a href=\"asfsf\">link</a>sfasffff"));
	}
}